/**
 * 轮播表管理初始化
 */
var LunboPic = {
    id: "LunboPicTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
LunboPic.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '图片路径', field: 'path', visible: true, align: 'center', valign: 'middle'},
        {title: '机构Id', field: 'infoId', visible: false, align: 'center', valign: 'middle'},
        {title: '机构', field: 'orgName', visible: true, align: 'center', valign: 'middle'},
        {title: '轮播图类型', field: 'typeId', visible: true, align: 'center', valign: 'middle'},
        {title: '轮播图1', field: 'picture1', visible: true, align: 'center', valign: 'middle'},
        {title: '轮播图2', field: 'picture2', visible: true, align: 'center', valign: 'middle'},
        {title: '轮播图3', field: 'picture3', visible: true, align: 'center', valign: 'middle'},
        {title: '轮播图4', field: 'picture4', visible: true, align: 'center', valign: 'middle'},
        {title: '轮播图5', field: 'picture5', visible: true, align: 'center', valign: 'middle'},
        {title: '用户', field: 'userId', visible: true, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
LunboPic.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        LunboPic.seItem = selected[0];
        return true;
    }
};

/**
 * 管理员点击添加主页轮播表
 */
LunboPic.openAddLunboPic = function () {
    var index = layer.open({
        type: 2,
        title: '添加轮播表',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/lunboPic/lunboPic_add'
    });
    this.layerIndex = index;
};
/**
 * 管理员点击添加客户轮播表
 */
LunboPic.openUserAddLunboPic = function () {
    var index = layer.open({
        type: 2,
        title: '会员添加轮播表',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/lunboPic/lunboPic_user_add'
    });
    this.layerIndex = index;
};
/**
 * 用户点击添加客户轮播表
 */
LunboPic.openUserAddLunboPic1 = function () {
    var index = layer.open({
        type: 2,
        title: '会员添加轮播表',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/lunboPic/lunboPic_user_add1'
    });
    this.layerIndex = index;
};
/**
 * 打开查看轮播表详情
 */
LunboPic.openLunboPicDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '轮播表详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/lunboPic/lunboPic_update/' + LunboPic.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除轮播表
 */
LunboPic.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/lunboPic/delete", function (data) {
            Feng.success("删除成功!");
            LunboPic.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("lunboPicId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询轮播表列表
 */
LunboPic.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    LunboPic.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = LunboPic.initColumn();
    var table = new BSTable(LunboPic.id, "/lunboPic/list", defaultColunms);
    table.setPaginationType("client");
    LunboPic.table = table.init();
});
